package by.grsu.samusev.page.pages;

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.SubmitLink;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.model.CompoundPropertyModel;

import by.grsu.samusev.app.SamusevWebApplication;
import by.grsu.samusev.dao.impl.VoyageDao;
import by.grsu.samusev.entity.Voyage;



public class VoyageEditPage extends WebPage {
	public VoyageEditPage(final Voyage voyage){
		super();
		
		final Form<Voyage> form = new Form<Voyage>("form", new CompoundPropertyModel<Voyage>(voyage));
		add(form);
		
		form.add(new TextField<Boolean>("Status"));
		form.add(new TextField<String>("DriverId"));
		
		form.add(new SubmitLink("Save"){
			@Override
			public void onSubmit(){
				super.onSubmit();
				
				final VoyageDao voyageDao = new VoyageDao(SamusevWebApplication.DATA_XML_FOLDER);
				
				if (voyage.getId() == null){
					voyageDao.saveNew(voyage);
				} else {
					voyageDao.update(voyage);
				}
				
				setResponsePage(new VoyageListPage());
				System.out.println("button Save pressed");
			}
		});
		
		form.add(new Link("Cancel"){
			@Override
			public void onClick(){
				setResponsePage(new VoyageListPage());
				System.out.println("button Cancel pressed");
			}
		});
	}
}